/**********************************************************************
*  Copyright (c) 2007 - Victor Jacobs - victor.jacobs@gmail.com
*
*  Permission is hereby granted, free of charge, to any person
*  obtaining a copy of this software and associated documentation
*  files (the "Software"), to deal in the Software without
*  restriction, including without limitation the rights to use,
*  copy, modify, merge, publish, distribute, sublicense, and/or sell
*  copies of the Software, and to permit persons to whom the
*  Software is furnished to do so, subject to the following
*  conditions:
*
*  The above copyright notice and this permission notice shall be
*  included in all copies or substantial portions of the Software.
*
*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
*  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
*  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
*  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
*  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
*  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
*  OTHER DEALINGS IN THE SOFTWARE.
**********************************************************************/

using System;
using System.Collections.Generic;
using System.Text;
using Vj.Ann;

namespace Vj.AnnTesterTool
{
    public class Program
    {
        static void Main(string[] args)
        {
            // ******************************
            //    Create training patterns
            // ******************************

            List<Pattern> patternList = new List<Pattern>();

            int numOfPatterns = (int)Math.Pow(2.0, 2.0 * 5.0);
            List<Pattern> patternsToTest = PatternBuilder.ONESPattern(5, numOfPatterns);

            Random rg = new Random();

            for (int i = 0; i < 500000; i++)
            {
                int next = rg.Next(numOfPatterns);
                patternList.Add(patternsToTest[next]);
            }

            // ******************************
            //    Create Network
            // ******************************

            BaseNetwork network = BaseNetwork.Create(new int[] { 5, 13, 1 }, 0.75, 0.0, 1.0);

            // ******************************
            //    Train Network
            // ******************************

            DateTime EventTime1 = DateTime.Now;

            network.Train(patternList);

            DateTime EventTime2 = DateTime.Now;
            
            TimeSpan elapsed = EventTime2 - EventTime1;

            // ******************************
            //    Test Network
            // ******************************

            Pattern testPattern = new Pattern(5, 1);
            testPattern.Inputs = new double[] { 1.0, 1.0, 0.0, 1.0, 1.0 };
            testPattern.Outputs = new double[] { 0.8 };

            network.Test(testPattern);

            // ******************************
            //    Display Result
            // ******************************

            Console.Out.WriteLine("Expected: " + network.OutputLayer.Neurons[0].ExpectedValue);
            Console.Out.WriteLine("Actual: " + network.OutputLayer.Neurons[0].Output);

            Console.Out.WriteLine("Time: (seconds) " + elapsed.TotalSeconds );

            string tmp = Console.In.Read().ToString();
        }


  

    }
}
